#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>

int main(void)
{
	int fd;
	int ret;
	struct input_event event;
	
	fd = open("/dev/input/event1", O_RDWR);
	if(fd < 0)
	{
		perror("open");
		exit(1);
	}


	/*
		#define KEY_VOLUMEDOWN		114   K4
		#define KEY_VOLUMEUP		115   K3
		#define KEY_POWER		    116   K2
	*/	
	while(1)
	{
		ret = read(fd, &event, sizeof(struct input_event));
		if(ret < 0)
		{
			perror("read");
			exit(1);
		}

		if(event.type == EV_KEY)
		{
		   switch(event.code){
				case KEY_POWER:
					if(event.value){ //按下
						printf("__APP_USER__ :	K2 power pressed\n");

					}else{
						printf("__APP_USER__ :	K2 power up\n");
					}
					break;
				case KEY_VOLUMEDOWN:
					if(event.value){ //按下
						printf("__APP_USER__ :	K4 KEY_VOLUMEDOWN pressed\n");

					}else{
						printf("__APP_USER__ :	K4 KEY_VOLUMEDOWN up\n");
					}
					break;
				case KEY_VOLUMEUP:
					if(event.value){ //按下
						printf("__APP_USER__ :	K3 KEY_VOLUMEUP pressed\n");

					}else{
						printf("__APP_USER__ :	K3 KEY_VOLUMEUP up\n");
					}
					break;
			
			}

		}
		
	}


	close(fd);

	return 0;
}








